package com.vision.mapper;

import com.vision.pojo.entity.LikeVideo;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

/**
 * @projectName: vision
 * @package: com.vision.mapper
 * @className: LikeVideoMapper
 * @author: escapeicon@gmail.com
 * @description: 视频点赞数据访问层
 * @date: 2024/1/25 15:34
 * @version: 1.0
 */
@Mapper
public interface LikeVideoMapper {

    /**
     * 添加点赞记录
     * @param userId 用户id
     * @param videoId 视频id
     * @return 结果
     */
    @Insert("insert into vs_like_video (user_id, video_id,create_time) values (#{userId},#{videoId},now())")
    void insert(Integer userId, Integer videoId);

    /**
     * 删除点赞记录
     * @param videoId 视频id
     */
    @Delete("delete from vs_like_video where video_id = #{videoId}")
    void deleteByVideoId( Integer videoId );

    /**
     * 删除点赞记录
     * @param userId 用户id
     * @param videoId 视频id
     */
    @Delete("delete from vs_like_video where user_id = #{userId} and video_id = #{videoId}")
    void deleteByVideoIdAndUserId (Integer userId, Integer videoId);

    /**
     * 查询视频点赞数
     * @param videoId 视频id
     * @return 点赞数
     */
    @Select("select count(*) from vs_like_video where video_id = #{videoId}")
    Integer selectCountByVideoId(Integer videoId);

    /**
     * 查询是否点赞
     * @param userId 用户id
     * @param videoId 视频id
     * @return 是否点赞
     */
    @Select("select * from vs_like_video where user_id = #{userId} and video_id = #{videoId}")
    LikeVideo selectByUserIdAndVideoId(Integer userId, Integer videoId);
}
